package com.travel.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.travel.pojo.VenueShop;
import com.travel.service.impl.VenueServiceImpl;
import com.travel.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class VenueController {
    @Autowired
    private VenueServiceImpl venueService;
    @GetMapping("/venue/selectAll")
    public Result getElement() {
        List<VenueShop> shopList = venueService.list();
        List<StringBuilder> stringBuilders = venueService.processVenueShopList(shopList);
        return new Result(stringBuilders, "查询成功", 200);
    }
    @GetMapping("/venue/search")
    public Result searchElement(String ele){
        QueryWrapper<VenueShop> wrapper = new QueryWrapper<>();
        wrapper.like("shop_name",ele).or().like("shop_address",ele);
        List<VenueShop> list = venueService.list(wrapper);
        List<StringBuilder> stringBuilders = venueService.processVenueShopList(list);
        return new Result<>(stringBuilders,"查询成功",200);
    }
    @GetMapping("/venue/listSelection")
    public Result listSelection(int distance,String type,int money){
        QueryWrapper<VenueShop> wrapper = new QueryWrapper<>();
        if (distance > 0) {
            if (money <= 10) {
                wrapper.gt("distance", 10);
            } else if (money <= 20) {
                wrapper.between("distance", 10, 20);
            } else {
                wrapper.gt("distance", 20);
            }
        }
        if (StringUtils.isNotBlank(type)) {
            wrapper.eq("shop_type", type);
        }
        if (money > 0) {
            if (money <= 50) {
                wrapper.gt("cpp", 50);
            } else if (money <= 200) {
                wrapper.between("cpp", 50, 200);
            } else {
                wrapper.gt("cpp", 200);
            }
        }
        List<VenueShop> list = venueService.list(wrapper);
        List<StringBuilder> stringBuilders = venueService.processVenueShopList(list);
        return new Result<>(stringBuilders,"查询成功",200);
    }
}
